<?php
/**
 * Created by PhpStorm.
 * User: HS032
 * Date: 2020/7/7
 * Time: 10:36
 */

namespace app\models;


class OrderSearch extends OrderInfo
{
    public function rules()
    {
        return [
            ['pay_order_sn','string'],
            ['mar_order_sn','string'],
            ['pay_status','in','range' => ['1','2','3','4','5']],
            ['success_time','string'],
        ];
    }


    public function search($params)
    {
        if (isset($params['pay_order_sn']) and !empty($params['pay_order_sn'])){
            $params['OrderSearch']['pay_order_sn'] = $params['pay_order_sn'];
        }else{
            $params['OrderSearch']['pay_order_sn'] = '';
        }
        if (isset($params['mar_order_sn']) and !empty($params['mar_order_sn'])){
            $params['OrderSearch']['mar_order_sn'] = $params['mar_order_sn'];
        }else{
            $params['OrderSearch']['mar_order_sn'] = '';
        }
        if (isset($params['status']) and !empty($params['status'])){
            $params['OrderSearch']['pay_status'] = $params['status'];
        }


        $query = OrderInfo::find();

        if ($this->load($params) and $this->validate()){
            if (!empty($params['OrderSearch']['pay_order_sn'])){
                $query->andFilterWhere(['pay_order_sn' => $this->pay_order_sn]);
            }
            if (!empty($params['OrderSearch']['mar_order_sn'])){
                $query->andFilterWhere(['mar_order_sn' => $this->mar_order_sn]);
            }
            if (!empty($params['OrderSearch']['mar_order_sn'])){
                $query->andFilterWhere(['mar_order_sn' => $this->mar_order_sn]);
            }
            if (!empty($params['OrderSearch']['pay_status'])){
                $query->andFilterWhere(['pay_status' => $this->pay_status]);

            }
            if (!empty($params['start_time'])){
                $query->andFilterWhere(['>','success_time',$params['start_time']]);
            }
            if (!empty($params['end_time'])){
                $query->andFilterWhere(['<','success_time',$params['end_time']]);
            }

        }
        return $query;
    }
}